package gigapaint;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.io.Serializable;

public class MyRectangle implements Paintable, Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5027560716689428228L;
	private Point start, end;
	private Color lineColor, fillingColor;
	private int size;
	private boolean isFilled;

	public MyRectangle(Point start, Point end, Color lineColor,
			Color fillingColor, int size, boolean isFilled)
	{
		this.start = start;
		this.end = end;
		this.lineColor = lineColor;
		this.fillingColor = fillingColor;
		this.size = size;
		this.isFilled = isFilled;
	}

	@Override
	public void painting(Graphics2D g2d, boolean isDotted)
	{
		BasicStroke b;
		g2d.setPaint(lineColor);
		if (isDotted == true)
		{
			float[] dash = { 8.0f, 3.0f };
			b = new BasicStroke(size, BasicStroke.CAP_BUTT,
					BasicStroke.JOIN_BEVEL, 10.0f, dash, 0.0f);
		} else
		{
			b = new BasicStroke(size);
		}

		g2d.setStroke(b);
		if (start.x < end.x)
		{
			if (start.y < end.y)
				g2d.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);
			else
				g2d.drawRect(start.x, end.y, end.x - start.x, start.y - end.y);
		} else
		{
			if (start.y < end.y)
				g2d.drawRect(end.x, start.y, start.x - end.x, end.y - start.y);
			else
				g2d.drawRect(end.x, end.y, start.x - end.x, start.y - end.y);
		}
		if (isFilled == true)
		{
			g2d.setPaint(fillingColor);
			if (start.x < end.x)
			{
				if (start.y < end.y)
					g2d.fillRect(start.x, start.y, end.x - start.x, end.y
							- start.y);
				else
					g2d.fillRect(start.x, end.y, end.x - start.x, start.y
							- end.y);
			} else
			{
				if (start.y < end.y)
					g2d.fillRect(end.x, start.y, start.x - end.x, end.y
							- start.y);
				else
					g2d.fillRect(end.x, end.y, start.x - end.x, start.y - end.y);
			}
		}

	}

	public void setEnd(Point end)
	{
		this.end = end;
	}

}
